function initTable(tableName, selectType, dataAjax, aoColumns, btns, sUrl) {
	var language = navigator.browserLanguage ? navigator.browserLanguage
			: navigator.language;
	var oLanguage = getLanguage(language);

	var _table = $(tableName).DataTable({
		"aLengthMenu" : [ 10, 20, 40, 60 ],
		"searching" : false,// 禁用搜索
		"select" : {
			"style" : selectType
		},
		"lengthChange" : false,
		"paging" : true,// 开启表格分页
		"bProcessing" : true,
		"bServerSide" : true,
		"sPaginationType" : "full_numbers",
		"bAutoWidth" : false,
		"sort" : "position",
		"deferRender" : true,// 延迟渲染
		"bStateSave" : false, // 在第三页刷新页面，会自动到第一页
		"iDisplayLength" : 10,
		"iDisplayStart" : 0,
		"dom" : '<"toolbar">Bfrtip',
		"ordering" : false,// 全局禁用排序
		"ajax" : dataAjax,
		"aoColumns" : aoColumns,
		"buttons" : btns,
		"oLanguage" : oLanguage
	});

	_table.on('click', 'td.details-control', function() {
		var tr = $(this).closest('tr');
		var row = table.row(tr);
		if (row.child.isShown()) {
			row.child.hide();
			tr.removeClass('shown');
		} else {
			row.child(format(row.data())).show();
			tr.addClass('shown');
		}
	}).on('order.dt search.dt draw.dt', function() {
		_table.column(0, {
			search : 'applied',
			order : 'applied'
		}).nodes().each(function(cell, i) {
			// i 从0开始，所以这里先加1
			i = i + 1;
			// 服务器模式下获取分页信息，使用 DT 提供的 API 直接获取分页信息
			var page = table.page.info();
			// 当前第几页，从0开始
			var pageno = page.page;
			// 每页数据
			var length = page.length;
			// 行号等于 页数*每页数据长度+行号
			var columnIndex = (i + pageno * length);
			cell.innerHTML = columnIndex;
		});
	}).draw();
	return _table;
}

function jAlert(title, message, buttonLabel) {
	BootstrapDialog.alert({
		title : title,
		message : message,
		type : BootstrapDialog.TYPE_WARNING, // <-- Default value is
		// BootstrapDialog.TYPE_PRIMARY
		closable : true, // <-- Default value is false
		draggable : true, // <-- Default value is false
		closeByBackdrop : false,
		closeByKeyboard : false,
		buttonLabel : buttonLabel
	});

}

function jConfirm(title, message, buttonOkLabel, buttonCancelLabel, callbackFn) {
	BootstrapDialog.confirm({
		title : title,
		message : message,
		type : BootstrapDialog.TYPE_WARNING, // <-- Default value is
		// BootstrapDialog.TYPE_PRIMARY
		closable : true, // <-- Default value is false
		draggable : true, // <-- Default value is false
		closeByBackdrop : false,
		closeByKeyboard : false,
		btnCancelLabel : buttonCancelLabel, // <-- Default value is 'Cancel',
		btnOKLabel : buttonOkLabel, // <-- Default value is 'OK',
		btnOKClass : 'btn-warning', // <-- If you didn't specify it, dialog type
		// will be used,
		callback : callbackFn
	});
}

function getLanguage(language) {
	return {
		"sEmptyTable" : "没有查询到数据",
		"sInfo" : "从_START_到_END_条记录总记录数为_TOTAL_条",
		"sInfoEmpty" : "记录数为0",
		"sInfoFiltered" : "(全部记录数_MAX_条)",
		"sInfoPostFix" : "",
		"sInfoThousands" : ".",
		"sLengthMenu" : "显示_MENU_条",
		"sLoadingRecords" : "正在加载数据",
		"sProcessing" : "正在获取数据，请稍候",
		"sSearch" : "过滤名称",
		"sZeroRecords" : "没有找到数据",
		"oPaginate" : {
			"sFirst" : "首页",
			"sPrevious" : "上一页",
			"sNext" : "下一页",
			"sLast" : "尾页"
		},
		"oAria" : {
			"sSortAscending" : "升序",
			"sSortDescending" : "降序"
		}
	};
}
function openTab(url, title) {
	openLayerWindow(title, url);
}

function openLayerWindow(title, url) {
	layer.open({
		type : 2,
		title : title,
		shadeClose : true,
		shade : false,
		maxmin : true, // 开启最大化最小化按钮
		area : [ '893px', '600px' ],
		maxmin : true,
		content : url
	});
}

function openLayerTable(title, url) {

}

function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null)
		return unescape(r[2]);
	return null;
}

function ajaxPostForm(url, p1, p2, p3) {
	var tempForm = document.createElement("form");
	tempForm.id = "tempForm";
	tempForm.method = "post";
	tempForm.action = url;
	tempForm.target = "blank";

	var hideInput = document.createElement("input");
	hideInput.type = "hidden";
	hideInput.name = "add";
	hideInput.value = p1;
	tempForm.appendChild(hideInput);

	hideInput = document.createElement("input");
	hideInput.type = "hidden";
	hideInput.name = "all";
	hideInput.value = p2;
	tempForm.appendChild(hideInput);

	hideInput = document.createElement("input");
	hideInput.type = "hidden";
	hideInput.name = "form";
	hideInput.value = p3;
	tempForm.appendChild(hideInput);

	if (tempForm.attachEvent) { // IE
		tempForm.attachEvent("onsubmit", function() {
			window.open('about:blank', 'blank');
		});
	} else if (tempForm.addEventListener) { // DOM Level 2 standard
		tempForm.addEventListener("onsubmit", function() {
			window.open('about:blank', 'blank');
		});
	}
	document.body.appendChild(tempForm);
	if (document.createEvent) { // DOM Level 2 standard
		evt = document.createEvent("MouseEvents");
		evt.initMouseEvent("submit", true, true, window, 0, 0, 0, 0, 0, false,
				false, false, false, 0, null);
		tempForm.dispatchEvent(evt);
	} else if (tempForm.fireEvent) { // IE
		tempForm.fireEvent('onsubmit');
	}
	// 必须手动的触发
	tempForm.submit();
	document.body.removeChild(tempForm);

}

Date.prototype.format = function(fmt) {
	var o = {
		"M+" : this.getMonth() + 1, // 月份
		"d+" : this.getDate(), // 日
		"h+" : this.getHours(), // 小时
		"m+" : this.getMinutes(), // 分
		"s+" : this.getSeconds(), // 秒
		"q+" : Math.floor((this.getMonth() + 3) / 3), // 季度
		"S" : this.getMilliseconds()
	// 毫秒
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}
	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
					: (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}

function formatTableUnit(value, row, index) {
	return {
		css : {
			"width" : '150px',
			"white-space" : 'nowrap',
			"text-overflow" : 'ellipsis',
			"overflow" : 'hidden',
		}
	}
}
